<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .header{
            width: 100%;
            height: 40px;
            background-color: gray;
        }
        .weather_now{
            width: 300px;
            height: 40px;
            background-color: gray;
        }
        a{
            text-decoration: none;
            color:white;
            /* display: none; */
        }
        a img{
            position: relative;
            width: 30px;
            top: 7px;
        }
        a span{
            text-align: center;
            line-height: 10px;
            margin: 0 5px 0 0;
        }
        #Details_weather{
            width: 370px;
            display: none;
        }
        #Details_weather div{
            width: 120px;
            height: 200px;
            background-color: wheat;
            float: left;
            border: 1px solid gray;           
        }
        #Details_weather div span{
            display: block;
            width: 120px;
            height: 40px;
            line-height: 40px;
            text-align: center;
        }
    </style>
</head>
<body>
    <div class="header">
        <div  id="weather_now" class="weather_now">
            <a href="#">
                <span class="location">新乡：</span>
                <img src="" alt="" class="icon">
                <span class="temp">31°C</span>
                <span class="code_txt">晴</span>
                <span class="fl">32</span>
            </a>
        </div>
        <div id="Details_weather">
            <div class="every">
                
            </div>
            <div class="every">
                
            </div>           
            <div class="every">

            </div>
        </div>
    </div>
</body>
<script src="./jquery.js"></script>
<script src="./moment.js"></script>
<script>
    $(function(){
        $('.weather_now').mouseover(function(event){
            event.preventDefault()
			event.stopPropagation()
            $('#Details_weather').stop().slideDown(500)
        });
        $('#Details_weather').mouseleave(function(){
            event.preventDefault()
			event.stopPropagation()
            $('#Details_weather').stop().slideUp(500)
        })
        $('#Details_weather').mousemove(function(event){
            event.preventDefault()
			event.stopPropagation()
        })
        $.ajax({
            url: 'https://devapi.qweather.com/v7/weather/now?location=101180301&key=39bcfeeebb764c70ade129c2f821290b',
            method: 'get',
            success:function(res){
                var result_today = res.now
                // console.log(result_today);
                var icon_today = result_today.icon
                var temp_today = result_today.temp
                var code_txt_today = result_today.text
                var fl_today = result_today.feelsLike
                // console.log(icon_today,temp_today,code_txt_today,fl_today);
                $('.icon').attr('src',`./image/${icon_today}.png`)
                $('.temp').html(temp_today + '℃')
                $('.code_txt').html(code_txt_today)
                $('.fl').html(fl_today)
            },
            error: function(err){
                console.log(err);
            }
        })
    
        function get_weekDay(num){
            return moment(num).format('dddd')
        }
        $.ajax({
            url:'https://devapi.qweather.com/v7/weather/3d?location=101180301&key=39bcfeeebb764c70ade129c2f821290b',
            method:'get',
            success:function(res){
                var daily_list = res.daily
                // console.log(daily_list);
                $('.every').each(function(i){

                    var week_every = get_weekDay(daily_list[i].fxDate)
                    var icon_every = daily_list[i].iconDay
                    var temp_every = daily_list[i].tempMax
                    var textDay_every = daily_list[i].textDay
                    var wind_every = daily_list[i].windDirDay
                    $(this).empty
                    $(this).append(`
                        <span>${week_every}</span>
                        <span><img src="./image/${icon_every}.png" alt=""></span>
                        <span>${temp_every}°C</span>
                        <span>${textDay_every}</span>
                        <span>${wind_every}</span>
                    `)
                })
            },
            error:function(err){
                console.log(err);
            }
        })
    })
</script>
</html>